# class Solution(object):
#     def findPeakGrid(self, mat):
#         m = len(mat)
#         n = len(mat[0])
#         for i in range(m):
#             left = 0
#             right = n - 1
#             while left < right - 1:
#                 mid = (left + right) // 2
#                 if mat[i][mid] > mat[i][mid - 1]:
#                     if mat[i][mid] > mat[i][mid + 1]:
#                         break
#                     else:
#                         left = mid
#                 else:
#                     if mat[i][mid] > mat[i][mid + 1]:
#                         right = mid
#                     else:
#                         left = mid
#             if right - left <= 1:
#                 if mat[i][right] > mat[i][left]:
#                     mid = right
#                 else:
#                     mid = left
#             flag = True
#             if i > 0:
#                 if mat[i][mid] < mat[i - 1][mid]:
#                     flag = False
#             if i < m - 1:
#                 if mat[i][mid] < mat[i + 1][mid]:
#                     flag = False
#             if flag:
#                 return [i, mid]
#         max_val = max([max(mat[i]) for i in range(m)])
#         for i in range(m):
#             for j in range(n):
#                 if mat[i][j] == max_val:
#                     return [i, j]

class Solution(object):
    def findPeakGrid(self, mat):
        m = len(mat)
        n = len(mat[0])
        left = 0
        right = m - 1
        while left < right - 1:
            mid = (left + right) // 2
            j = mat[mid].index(max(mat[mid]))
            if mat[mid][j] > mat[mid - 1][j]:
                if mat[mid][j] > mat[mid + 1][j]:
                    return [mid, j]
                else:
                    left = mid + 1
            else:
                if mat[mid][j] > mat[mid + 1][j]:
                    right = mid - 1
                else:
                    left = mid + 1
        left_max = mat[left].index(max(mat[left]))
        right_max = mat[right].index(max(mat[right]))
        if mat[left][left_max] > mat[right][right_max]:
            return [left, left_max]
        else:
            return [right, right_max]



